<%@ page language="java" isELIgnored="false" import="java.util.*"
	pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>收益人工数据导入</title>
<link href="<%=request.getContextPath()%>/fare/js/ligerUI/skins/Aqua/css/ligerui-all.css"
	rel="stylesheet" type="text/css" />
<link href="<%=request.getContextPath()%>/fare/js/ligerUI/skins/ligerui-icons.css" rel="stylesheet"
	type="text/css" />
<link href="<%=request.getContextPath()%>/fare/js/ligerUI/skins/Gray/css/all.css" rel="stylesheet"
	type="text/css" />
<script src="<%=request.getContextPath()%>/fare/lib/jquery/jquery-1.3.2.min.js"
	type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/fare/js/ligerUI/js/core/base.js" type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/fare/js/ligerUI/js/plugins/ligerGrid.js"
	type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/fare/js/ligerUI/js/plugins/ligerToolBar.js"
	type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/fare/js/ligerUI/js/plugins/ligerResizable.js"
	type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/fare/js/ligerUI/js/plugins/ligerCheckBox.js"
	type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/fare/js/ligerUI/js/plugins/ligerDateEditor.js"
	type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/fare/js/ligerUI/js/plugins/ligerDialog.js"
	type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/fare/js/ligerUI/js/plugins/ligerComboBox.js"
	type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/fare/js/ligerUI/js/plugins/ligerSpinner.js" 
	type="text/javascript"></script>
<script type='text/javascript' src='<%=request.getContextPath()%>/fare/js/ajaxfileupload.js'></script>
	
<link href='<%=request.getContextPath()%>/fare/js/cityquery/cityquery.css' rel="stylesheet" type="text/css" />
<script type='text/javascript' src='<%=request.getContextPath()%>/fare/js/cityquery/citylist.js'></script>
<script type='text/javascript' src='<%=request.getContextPath()%>/fare/js/cityquery/querycity.js'></script>


<link rev="stylesheet" media="all" href="<%=request.getContextPath() %>/fare/css/form_style.css" type="text/css" rel="stylesheet">

<!-- 圆角文本框 -->
<link href="<%=request.getContextPath() %>/fare/css/htc/htc.css" rel="stylesheet" type="text/css" />
<script type="text/javascript"
	src="<%=request.getContextPath() %>/jsFile/wait/js/wait.js"></script>

<script type="text/javascript">
function ajaxFileUpload()
{
	var flag=confirm("确认上传？");
	if(!flag){
		return false;
	}
    $("#loading")
    .ajaxStart(function(){
    	FDCDialog.show();
    })//开始上传文件时显示一个图片
    .ajaxComplete(function(){
       // $(this).hide();
    });//文件上传完成将图片隐藏起来
    
    $.ajaxFileUpload
    (
        {
            url:'<%=request.getContextPath() %>/plane/income/plfimport/excelImport.action',//用于文件上传的服务器端请求地址
            secureuri:false,//一般设置为false
            fileElementId:'uploadFile',//文件上传空间的id属性  <input type="file" id="file" name="file" />
            dataType: 'json',//返回值类型 一般设置为json
            success: function (data, status)  //服务器成功响应处理函数
            {   
            	//alert(data);
            	FDCDialog.hide();
            //	alert("操作完成");
           // 	location.href = "/taluo-web/fare/_syrgdrsj.jsp";
                 if(data && data.hasOK)
                {
                	alert("import success");
                  //
                }
                else{
                	//$("#test1").html(data.bean);
               	$.ligerDialog.error(data.bean,"导入错误");
                //	alert("import success");
                	 //$.ligerDialog.open({ target: $("#target1") });
                	 
                	//alert(data.bean);
                } 
            },
            error: function (data, status, e)//服务器响应失败处理函数
            {
                alert(data);
            }
        }
    )
    
    return false;

}
</script>


<script type="text/javascript">
	var air_listStrs=null;
	var flight_listStrs=null;
	//初始化列表信息 
	$(function() {
		$.getJSON('<%=request.getContextPath()%>/occupRateAction!initAirCom.action', function(air_listStr) {
			air_listStrs=air_listStr;
			$('#queryCom').ligerComboBox({
				selectBoxHeight :'300px',
				data : air_listStrs,
				initValue:'',
				textField : 'name',
				valueField : 'id',
				onSelected : function(value, text) {
					$('#queryCom').attr('value', text);
					$('#queryComVal').attr('value', value);
				}
		});
		
		
	});	
	});
	//获取选中行信息
	function getSelect() {
		var row = manager.getSelectedRow();
		if (!row) {
			$.ligerDialog.warn('请选您要操作的行！');
			return;
		} 
			return eval('(' + JSON.stringify(row) + ')');
		
	}
	
	//保存航空公司信息 
	var air_list=null;
	//初始化航空公司选择下拉列表
	
	 var cmb1, cmb2;
	//增加
	function add(){
		cmb1=$('#companyName').ligerComboBox({
				isMultiSelect: false,
				data : air_listStrs,
				textField : 'name',
				valueField : 'id',
				onSelected : function(value, text) {
					cmb2.clearContent();
					$("#flightInfo").val("");
					$("#lineCode").val("");
					$('#companyCode').attr('value', value);
					setdata(cmb2, '<%=request.getContextPath()%>/occupRateAction!initFlightInfo.action?flightNo='+value);
				}
		});
		
		cmb2=$('#flightInfo').ligerComboBox({
			data : null,
			initText : '请选择',
			textField : 'flightNo',
			valueField : 'flightName',
			onSelected : function(value, text) {
				$('#flightInfo').attr('value', text);
				$('#lineCode').attr('value', value);
			}
		});
		
		openAdd();
	}
	
	 function setdata(obj, url) {
	        $.getJSON(url,
	                     function(flight_listStr) {
	                         obj.setData(flight_listStr); //把json塞到下拉框里面去
	                         //            $("#txtjson").val(JSON2.stringify(json)); 
	                     }
	   );
	 }
	
	
	function openAdd() {
		$('#companyName').show();
		$('#flightInfo').attr('value', '');
		$('#lineCode').attr('value', '');
		$('#flightDay').attr('value', '');
		$('#price').attr('value', '');
		$('#occupRate').attr('value', '');
		$('#income').attr('value', '');
		var addLine = $('#addLine');
		$.ligerDialog.open({
			width : 300,
			height :250,
			target : addLine,
			title : '增加收益数据',
			buttons : [ {
				text : '确定',
				onclick : function(item, dialog) {
					if(checkForm()){
						dialog.hidden();
						$.ajax({
							cache : false,
							type : "post",
							data: $('#editForm').serialize(), 
							url : "<%=request.getContextPath()%>/occupRateAction!save.action",
							success : function(data){
								$.ligerDialog.alert('添加成功！', '提示', "success",function(){
									location.href = "/taluo-web/fare/_syrgdrsj.jsp";
								})
							},
							error : function(){
								$.ligerDialog.error('服务器出错，操作失败，请重试!');
								}
						});
					}

				}
			}, {
				text : '取消',
				onclick : function(item, dialog) {
					$('#editForm span').text('');
					dialog.hidden();
				}
			} ]
		});
	}
	
	//下载模版
	function templateDownload(){
		window.location.href ="<%=request.getContextPath() %>/plane/income/plfimport/dataTemplate.action";
	}

    //上传文件
	function uploadSubmit(){
		$.post("<%=request.getContextPath() %>/plane/income/plfimport/excelImport.action",
			{"uploadFile":$("#uploadFileBtn").val()},
	        function(data){
	     alert("data");
	   }, "text");
}
    
    function checkFrom2(){
    	var flag2=true;
    //	if($("#uploadfile").text('uploadfile[]').val=='')
    	var ff = document.getElementsByName("'uploadfile[]");
    //	alert(ff[1].value);
    	alert('上传文件不能为空');
    	flag2=false;
    }
    
	//验证非空 
	function checkForm() {
		var flag=true;
		if ($("#companyName").val() == '' || $("#companyName").val()=='请选择') {
			$('#companyNameTxt').text('不能为空 ');			
			flag=false;
		}else{
			$('#companyNameTxt').text('');
		}
		if ($.trim($("#flightInfo").val()).length == 0 || $("#flightInfo").val()=='请选择') {
			$('#flightInfoTxt').text('不能为空 ');
			flag=false;
		}else{
			$('#flightInfoTxt').text('');
		}
		if ($.trim($("#lineCode").val()).length == 0) {
			$('#lineCodeTxt').text('不能为空 ');
			flag=false;
		}else{
			$('#lineCodeTxt').text('');
		}
		if ($.trim($("#flightDay").val()).length == 0) {
			$('#flightDayTxt').text('不能为空 ');
			flag=false;
		}else{
			$('#flightDayTxt').text('');
		}
		if ($.trim($("#price").val()).length == 0) {
			$('#priceTxt').text('不能为空 ');
			flag=false;
		}else{
			$('#priceTxt').text('');
		}
		if ($.trim($("#occupRate").val()).length == 0) {
			$('#occupRateTxt').text('不能为空 ');
			flag=false;
		}else{
			$('#occupRateTxt').text('');
		}
		if($.trim($("#occupRate").val()) >=100){
			$('#occupRateTxt').text('不能大于100 ');
			flag=false;
		}
		
		if ($.trim($("#income").val()).length == 0) {
			$('#incomeTxt').text('不能为空 ');
			
			flag=false;
		}else{
			$('#incomeTxt').text('');
		}
		return flag;
		
	}
	
	//删除节假日
	function del() {
		var row = getSelect();
		$.ligerDialog.confirm('确定要删除数据？',function(yes) 
			{
				if (yes) {
					$.ajax({
						type : "post",
						url : "<%=request.getContextPath()%>/occupRateAction!deleteOccup.action?occupRateEntityVO.id=" + row.id,
						cache : false,
						success : function(data){
							location.href = "/taluo-web/fare/_syrgdrsj.jsp";
						},
						error : function(){
							$.ligerDialog.error('服务器出错，操作失败，请重试!');
						}
					});
				}
			});
	}
	
	//修改节假日
	function edit() {
		var row= getSelect();
		if(row){
			$('#companyCode').attr('value', row.companyCode);
			var seldata=$('#companyCode').val();
			cmb1=$('#companyName').ligerComboBox({
				data : air_listStrs,
				textField : 'name',
				valueField : 'id',
				initValue:seldata,
				onSelected : function(value, text) {
					cmb2.clearContent();
					$("#flightInfo").val("");
					$("#lineCode").val("");
					$('#companyCode').attr('value', value);
					setdata(cmb2, '<%=request.getContextPath()%>/occupRateAction!initFlightInfo.action?flightNo='+value);
				}
			});
			
			//如果修改有值  也要加载第二个列表的值 
			if($.trim($("#companyName").val()).length != 0){
				var seldata=$('#companyCode').val();
				setdata(cmb2, '<%=request.getContextPath()%>/occupRateAction!initFlightInfo.action?flightNo='+seldata);
			}
		
			cmb2=$('#flightInfo').ligerComboBox({
				data : null,
				textField : 'flightNo',
				valueField : 'flightName',
				initValue:row.flightName,
				onSelected : function(value, text) {
					$('#flightInfo').attr('value', text);
					$('#lineCode').attr('value', value);
				}
			});
			$('#lineName').attr('value', row.lineName);
			$('#flightName').attr('value', row.flightName);
			$('#flightDay').attr('value', row.flightDay);
			$('#price').attr('value', row.price);
			$('#occupRate').attr('value', row.occupRate);
			$('#income').attr('value', row.income);
			$('#id').attr('value', row.id);
			var addLine = $('#addLine');
			$.ligerDialog.open({
				width : 300,
				height :250,
				target : addLine,
				title : '修改',
				buttons : [ {
					text : '确定',
					onclick : function(item, dialog) {
						if(checkForm()){
							dialog.hidden();
							$.ajax({
								cache : false,
								type : "post",
								data: $('#editForm').serialize(), 
								url : "<%=request.getContextPath()%>/occupRateAction!save.action",
								success : function(data){
									$.ligerDialog.alert('修改成功', '提示', "success",function(){
										location.href = "/taluo-web/fare/_syrgdrsj.jsp";
									});
								},
								error : function(){
									$.ligerDialog.error('服务器出错，操作失败，请重试!');
									}
							});
						}
					}
				}, {
					text : '取消',
					onclick : function(item, dialog) {
						$('#editForm span').text('');
						dialog.hidden();
					}
				} ]
			});
		}else
			return;
	}

	//初始化安排假期表格
	$(function() {
		//初始换日期选择框
		$("#flightDay").ligerDateEditor({
			showTime : true,
			label : '带时间',
			labelWidth : 100,
			labelAlign : 'left'
		});
		
		$("#queryDate").ligerDateEditor({
			labelWidth : 100,
			labelAlign : 'left'
		});
		
		//只能輸入數字
		$("#income").ligerSpinner({
			 isNegative:false,
			 type : 'float'
		});
		
		$("#occupRate").ligerSpinner({
			 isNegative:false,
			 type : 'float'
		});
		
		$("#price").ligerSpinner({
			 isNegative:false,
			 type : 'float'
		});
	});
	
	function find(){	
		var url = "<%=request.getContextPath()%>/occupRateAction!show.action"; 
		
		   var queryComVal=$.trim($("#queryComVal").val());	
		   var queryDate=$.trim($("#queryDate").val());	
		   var depCity=$.trim($("#depCity").val());	
		   var arrCity=$.trim($("#arrCity").val());	
		    	var jspData={queryComVal:queryComVal,queryDate:queryDate,depCity:depCity,arrCity:arrCity};
		    	var tbQueryDetail = JSON.stringify(jspData);    //将JSON对象转变成JSON格式的字符串
		        
		    	 var parms=[
		    	            {name : 'jspData',value : tbQueryDetail}
		    	        ];//查询条件
		    	 manager.setOptions({
		   	            parms:parms,
		   	            url:url, //指定url
		   	         	newPage:1, //指向第1页
		   	            enabledEdit: true,
		   	            clickToEdit:false, 
		   	            dataAction:"server",
		   	            dataType:"server"
		   	        });
		    	 manager.loadData();  //加载数据
		}
	
	//初始化起始和到达城市 
	$(function(){
		
		$('#depCity').querycity({'data':citysFlight,'tabs':labelFromcity,'hotList':hotList});
		$('#arrCity').querycity({'data':citysFlight,'tabs':labelFromcity,'hotList':hotList});

		//刚开始查找所有数据 
		var url = "<%=request.getContextPath()%>/occupRateAction!show.action";
		manager = window['g'] = $("#maingrid").ligerGrid({
			columns : [ {
				display : '航班公司',
				name : 'companyName',
				width : 110,
				minWidth : 60
			}, {
				display : '航线',
				name : 'lineCode',
				minWidth : 120
			}, {
				display : '航班',
				name : 'flightInfo',
				minWidth : 120
			}, {
				display : '航班时间',
				name : 'flightDay',
				type : 'date',
				format : 'yyyy-MM-dd HH:mm'
			}, {
				display : '航班价格',
				name : 'price'
			},{
				display : '客座率',
				name : 'occupRate',
				render: function (record, rowindex, value, column) {
					if (!value) return "0%"; 
					
					if (isNaN(value)) 
						value=value*100;
					
                     return value+"%";
                }

			},{
				display : '收益',
				name : 'income'
			} ],
		  //url: url,
			height : '100%',
			rownumbers : true,
	        pageSizeOptions : [10,30,50,100],
   			pageSize : 10,
   	       	pageParmName : 'pageNum',
            pagesizeParmName:'pageSize',
			toolbar : {
				items : [ {
					text : '增加',
					click : add,
					icon : 'add'
				}, {
					line : true
				}, {
					text : '修改',
					click : edit,
					icon : 'modify'
				}, {
					line : true
				}, {
					text : '删除',
					click : del,
					img : '<%=request.getContextPath()%>/fare/js/ligerUI/skins/icons/delete.gif'
				} ]
			},
			onLoading: function () {
			    $('.ligerGrid-toolbar').append($('#searchTable'));
			    $('#searchTable').show(); 		    
			}
			
		});
		
		find();
	
		
	});
</script>

<script type="text/javascript">	
	function showTr(){
		if(f1.show1.value=='批量导入数据'){
			f1.show1.value='隐藏批量导入';  
			lead2.style.display='';
		}else{
			f1.show1.value='批量导入数据'; 
			lead2.style.display='none'
		}
	}

</script>


</head>
<body>
<div class="form_table_tltle">查询条件 </div>
<form action="../occupRateAction!show.action" method="post" id="queryForm" name="f1">
	<table id="searchTable" class="form_table"  width="100%" border=0 name="f2">
		<tr>
			<td  height="26" class="left" style="text-align: left" width="120">&nbsp;航班公司:</td>
			<td><input id="queryCom" name="queryCom"/>
			<input type="hidden" id="queryComVal" name="queryComVal"/>
			 </td>
			<!-- <td><input type="text" id="queryLine" name="queryLine"/> </td> -->
			<TD class="left" width="120">航段：</TD>
   			 <TD>
     		<%--  <span>从</span>
     		 <input type="text" style="width:100px" name="depCity" id="depCity" >
      		<span>到</span>
      		<input type="text" style="width:100px" name="arrCity" id="arrCity" > --%>
      		<jsp:include page="../inc/flightSelect.jsp">
	    <jsp:param value="${fromCity}" name="fromCity"/>
	    <jsp:param value="${fromCityCode}" name="fromCityCode"/>
	    <jsp:param value="${toCity}" name="toCity"/>
	    <jsp:param value="${toCityCode}" name="toCityCode"/>
 </jsp:include>
   			 </TD>
		</tr>
		<tr>
		<td class="left" width="120">&nbsp;日期:</td>
			<td><input  id="queryDate" name="queryDate" readonly="true" /> </td>
		 <td height="26" colspan="2" align="center"><input type="button" value="查询" onclick="javascript:find();" />
		 <input type="button" value="批量导入数据" name="show1"  onclick=" javascript:showTr()" />  
		 </td>
		</tr>

		<TR id="lead2" style="display:none" >
		    <TD  style="text-align: center;width: 120" height="26">
		    <input type="button" onclick="templateDownload()"  value="" class="btn17" />
		    </TD>
		    <td  style="text-align: right; width:120"  height="26">
		    	 导入文件:
		    </td>
		    <td  style="text-align: left;" width: 120"  height="26">
		    	<img src="<%=request.getContextPath()%>/images/um/ajaxLoader.gif" id="loading" style="display: none;" >
		    	<input type="file" id="uploadFile" name="uploadFile" >
		    	
			</td>
			<td><input type="button" value="" class="btn14" onclick="return ajaxFileUpload();" ></td>
		</TR>
		
	</table>
</form>
	<div id="maingrid" width="100%" border="1" cellpadding="4" CELLSPACING="1" class="tabg"></div>
	<div id="addLine"
		style="height: 200px; width: 250px; margin: 3px; display: none;">
		<form action="#" method="post" id="editForm">
			<table>
				<tr id="trcompanyName" style="height: 35px; margin: 20px;">
					<td align="right">航班公司:</td>
					<td><input type="text" id="companyName" name="occupRateEntityVO.companyName"></td>
					<td><span id="companyNameTxt" style="color:red"></span></td>
				</tr>
				<tr style="height: 25px; margin: 35px;">
					<td align="right">航班:</td>
					<td><input type="text" id="flightInfo" name="occupRateEntityVO.flightInfo"></td>
					<td><span id="flightInfoTxt" style="color:red"></span></td>
				</tr>
				
				<tr style="height: 25px; margin: 35px;">
					<td align="right">航线:</td>
					<td><input type="text" id="lineCode"
						name="occupRateEntityVO.lineCode" readonly="true"></td>
					<td><span id="lineCodeTxt" style="color:red"></span></td>
				</tr>

				<tr style="height: 25px; margin: 35px;">
					<td align="right">航班时间:</td>
					<td><input type="text" id="flightDay"
						name="flightDate" readonly="true"></td>
					<td><span id="flightDayTxt" style="color:red"></span></td>
				</tr>
				<tr style="height: 25px; margin: 35px;">
					<td align="right">航班价格:</td>
					<td><input type="text" id="price"
						name="occupRateEntityVO.price" ></td>
					<td><span id="priceTxt" style="color:red"></span></td>
				</tr>
				<tr style="height: 25px; margin: 35px;">
					<td align="right">客座率:</td>
					<td><input type="text" id="occupRate"
						name="occupRateEntityVO.occupRate" ></td>
					<td><span id="occupRateTxt" style="color:red"></span></td>
				</tr>
				<tr style="height: 25px; margin: 35px;">
					<td align="right">收益:</td>
					<td><input type="text" id="income"
						name="occupRateEntityVO.income" ></td>
					<td><span id="incomeTxt" style="color:red"></span></td>
				</tr>
				<tr style="display: none;">
					<td>Id:</td>
					<td><input type="text" id="id" name="occupRateEntityVO.id"></td>
				</tr>
				
				<tr style="display: none;">
					<td>航班公司Code:</td>
					<td><input type="text" id="companyCode" name="occupRateEntityVO.companyCode"></td>
				</tr>
				
				<tr style="display: none;">
					<td>航班Code:</td>
					<td><input type="text" id="flightInfo" name="occupRateEntityVO.flightInfo"></td>
				</tr>
			</table>
		</form>
	</div>
	

</body>
</html>
